home *** CD-ROM | disk | FTP | other *** search
- Path: snews.tcel.com!netway
- From: tech@netway.ab.ca (Ritchie Annand)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Speed of C program vs. Speed of Pascal program
- Date: 10 Mar 1996 13:43:00 GMT
- Organization: Telnet Canada (403) 262-5859 info@tcel.com
- Message-ID: <4hum94$npg@challenge.tcel.com>
- References: <4hsf8p$c5d@caesar.ultra.net>
- NNTP-Posting-Host: 204.209.150.60
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4hsf8p$c5d@caesar.ultra.net>,
- kbrady@ultranet.com (Ken Brady) wrote:
- >I recently began learning to program in C/C++ after many years
- >of using Borland Turbo Pascal (v6.0). I have been porting a data analysis
- >program into C/C++, and notice that a subroutinefor reading large tables of
- >numbers (ASCII) and loading these numbers into (binary) arrays proceeds much
- >more rapidly in my C program than in my Pascal program. For one large
- table,
- >my Pascal program requires about 10 s to load the table, while the C program
- >loads it in less than 1 second.
- >
- >The I/O algorithms in these programs are essentially identical. I deduce
- >that the C atof function is much faster than the Pascal Val function. Is
- >this typical?
- >
- >My C/C++ compiler is Watcom 10.5, running under OS/2.
-
- Actually, that depends...
-
- It's quite possible atof is faster than Val - they are both library
- functions, after all, but generally speaking, you won't get a 10:1 speed ramp
- between the two from that sort of difference.
-
- It'd be my guess that you're using unbuffered Pascal I/O versus buffered C
- I/O... I've found that to be where most file-access differences lie:
-
- If your Pascal program uses:
- var
- f : Text;
-
- Then it's buffered (but not with a very large buffer - you can set it,
- though)
-
- If you use:
- var
- f : File;
- or
- f : File of Char;
- or
- f : File of MyRecord;
-
- Then it's unbuffered.
-
- With f : File, though, you do have the option of doing BlockRead and
- BlockWrite. Reset(f,SizeOf(MyRecord)) - if you're using a flat file of
- MyRecords, and BlockRead(f,MyRecordArray,NumberOfRecords,ActualRecordsRead) -
- that will give you some mighty good throughput ;)
-
- --=- Ritchie A.
-